﻿





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace InterfaceComponents
{
    /// <summary>
    /// Weaponbar is used in the HUD to display the level of its respective weapon.
    /// </summary>
    public class Weaponbar : InterfaceComponent, HUDComponent
    {
        private int value
        {
            get;
            set;
        }

        private Texture2D backroundTexture;

        private Texture2D barTexture;

        public Weaponbar(int val, Vector2 position, SpriteBatch spriteBatch)
        {
            this.value = val;
            this.position = position;
            this.spriteBatch = spriteBatch; 
            // create black backgroundtexture
            backroundTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            backroundTexture.SetData(new[] { Color.Black });
            // create red bar texture
            barTexture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            barTexture.SetData(new[] { Color.Red });
        }

        /// <summary>
        /// Draws the Weaponbar with the specified color.
        /// </summary>
        /// <param name="color">The color to tint the bartexture.</param>
        public override void Draw(Color color)
        {
            Rectangle dest = new Rectangle((int)position.X, (int)position.Y, 35, 16);
            spriteBatch.Draw(backroundTexture, dest, color);
            for (int i = 0; i < value + 1; i++)
            {
                 dest.X = (int)position.X + 4 + 8 * i;
                 dest.Y = (int)position.Y + 3;
                 dest.Width = 5;
                 dest.Height = 10;
                 spriteBatch.Draw(barTexture, dest, color);
            }
        }

        /// <summary>
        /// SetValue is used by the HUDWrapper to update th component.
        /// </summary>
        public virtual void SetValue(Object value)
        {
            if (value.GetType() == typeof(int))
            {
                this.value = (int)value;
            }
        }

    }
}

